package com.jiazhong.example.project.bookstore.backend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiazhong.example.project.bookstore.backend.service.SeckillService;
import com.jiazhong.example.project.bookstore.commons.bean.Seckill;
import com.jiazhong.example.project.bookstore.commons.mapper.SeckillMapper;
import com.jiazhong.example.project.bookstore.commons.util.DateUtil;
import com.jiazhong.example.project.bookstore.commons.util.JsonResult;
import com.jiazhong.example.project.bookstore.commons.util.ResultTool;
import org.springframework.stereotype.Service;

@Service
public class SeckillServiceImpl extends ServiceImpl<SeckillMapper, Seckill> implements SeckillService {

    @Override
    public JsonResult addSeckill(Seckill seckill) {
        return ResultTool.success(save(seckill));
    }

    @Override
    public JsonResult findAll() {
        return ResultTool.success(list());
    }

    @Override
    public JsonResult find() {
        QueryWrapper<Seckill> queryWrapper = new QueryWrapper<>();
        String nowDate = DateUtil.getNowDate();
        queryWrapper.ge("begin_time", nowDate);
        queryWrapper.le("end_time", nowDate);
        return ResultTool.success(this.list(queryWrapper));
    }
}
